<?php

/*
	Class: DealersViewDealersCountries

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>

	About: See Also
		- <Cts_Db_Table_Abstract>
*/
class DealersViewDealersCountries extends Cts_Db_Table_Abstract {

	/* Group: Instance Variables */

	/*
		Variable: $_name
	*/
	protected $_name = 'dealers_vw_dealers_countries';

	/*
		Variable: $_primary
	*/
	protected $_primary = array('dealer_id', 'country_code');

	/* Group: Instance Methods */

	/*
		Function: getByDealerId
			Retrieves an array of records joining dealers with categories.

		Arguments:
			dealer_id - The ID of the dealer for which to retrieve joins to country IDs.

		Returns: array of join data or empty array
	*/
	function getByDealerId($dealer_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('dealer_id = ?', $dealer_id));
		if (!is_null($tmp_joins)) {
			return $tmp_joins->toArray();
		} else {
			return array();
		}
	}

	/*
		Function: getCountryIdsByDealerId
			Retrieves an array of country IDs (country_code) which are associated to a given dealer.

		Arguments:
			dealer_id - The ID of the dealer for which to retrieve country IDs.

		Returns: array of country IDs
	*/
	function getCountryIdsByDealerId($dealer_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('dealer_id = ?', $dealer_id));
		if (!is_null($tmp_joins)) {
			$country_ids = array();
			foreach ($tmp_joins as $join) {
				$country_ids[] = $join->country_code;
			}
			return $country_ids;
		} else {
			return array();
		}
	}

	/*
		Function: getByCountryId
			Retrieves an array of records joining dealers with categories.

		Arguments:
			country_id - The ID of the country for which to retrieve joins to dealer IDs.

		Returns: array of join data or empty array
	*/
	function getByCountryId($cat_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('country_id = ?', $country_id));
		if (!is_null($tmp_joins)) {
			return $tmp_joins->toArray();
		} else {
			return array();
		}
	}

}
